/**
 * @author lzb
 */
var _dataUrl;
var _dataFormat;
var _myDataParam;
var _indexFunction;
var _postType = true;

GetPostUrl = function(dataUrl){
    var _dataUrl = dataUrl;
    var pos = dataUrl.indexOf("?");
    if (typeof(pos) != "undefined" && pos > 0) {
        _myDataParam = dataUrl.substr(pos + 1) + "&time=" + getTime();
        _dataUrl = dataUrl.substr(0, pos - 1);
    }
    else {
        _myDataParam = "time=" + getTime();
        
    }
    return _dataUrl;
}

GetPostFormat = function(dataFormat){
    var checkStr = "xml,josn,text";
    var pos = checkStr.indexOf(dataFormat.toLowerCase());
    if (typeof(pos) != "undefined" && pos >= 0) {
        _dataFormat = dataFormat.toLowerCase();
    }
    else {
        _dataFormat = "error";
    }
    return _dataFormat;
}

GetPostData = function(myDataParam){
    if (typeof(myDataParam) != "undefined" && myDataParam == "") {
    }
    else {
        _myDataParam += "&" + myDataParam;
    }
    return _myDataParam;
}

/**
 *
 * @param {Object} dataUrl   链接地址
 * @param {Object} dataFormat  获取数据格式
 * @param {Object} myDataParam  地址参数
 */
function getAjaxData(dataUrl, dataFormat, myDataParam, indexFunction, postType){

    _dataUrl = GetPostUrl(dataUrl);
    _dataFormat = GetPostFormat(dataFormat);
    
    if (typeof(postType) != "undefined" && postType != null) {
        if (postType == false) 
            _postType = postType;
    }
    else {
        _postType = true;
    }
    
    if (typeof(indexFunction) == "undefined" || indexFunction == "") {
        _indexFunction = "0";
    }
    else {
        _indexFunction = indexFunction;
    }
    //    	alert(indexFunction)
    //		alert(_indexFunction)
    if (_dataFormat == "error") {
        alert("输入数据格式错误，请检查输入数据！");
        return;
    }
    if (myDataParam == "") {
        _myDataParam = "time=" + getTime();
    }
    else {
        _myDataParam = myDataParam + "&time=" + getTime();
    }
    
    
    if (typeof(_myDataParam) == "undefined" || _myDataParam == "undefined") {
        _myDataParam = "time=" + getTime();
    }
    
    $.ajax({
        type: 'POST',
        url: _dataUrl,
        data: _myDataParam,
        dataType: _dataFormat,
        async: _postType,
        success: function(data){// 成功时候调用另外一个函数
            switch (_indexFunction) {
                case "1":
                    resultData1(data);
                    break;
                case "2":
                    resultData2(data);
                    break;
                case "3":
                    resultData3(data);
                    break;
                case "4":
                    resultData4(data);
                    break;
                case "5":
                    resultData5(data);
                    break;
                default:
                    resultData(data);
                    break;
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            //            if (XMLHttpRequest.responseText == "") 
            //                alert("error");
            //            else {
            //                alert(XMLHttpRequest.responseText);
            //            }
            //       alert("error");
        }
    });
}





/**
 *
 * @param {Object} dataUrl
 * @param {Object} dataFormat
 * @param {Object} myDataParam
 * @param {Object} indexFunction
 * @param {Object} postType
 */
function getAjaxData2(dataUrl, dataFormat, myDataParam, indexFunction, postType){
    _dataUrl = GetPostUrl(dataUrl);
    _dataFormat = GetPostFormat(dataFormat);
    
    if (typeof(postType) != "undefined" && postType != null) {
        if (postType == false) 
            _postType = postType;
    }
    else {
        _postType = true;
    }
    
    if (typeof(indexFunction) == "undefined" || indexFunction == "") {
        _indexFunction = "0";
    }
    else {
        _indexFunction = indexFunction;
    }
    if (_dataFormat == "error") {
        alert("输入数据格式错误，请检查输入数据！");
        return;
    }
    if (myDataParam == "") {
        _myDataParam = "time=" + getTime();
    }
    else {
        _myDataParam = myDataParam + "&time=" + getTime();
    }
    
    
    if (typeof(_myDataParam) == "undefined" || _myDataParam == "undefined") {
        _myDataParam = "time=" + getTime();
    }
    
    $.ajax({
        type: 'POST',
        url: _dataUrl,
        data: _myDataParam,
        dataType: _dataFormat,
        async: _postType,
        success: function(data){// 成功时候调用另外一个函数
            if (indexFunction == "") {
                newAjaxResult(data);
            }
            else {
                setTimeout(indexFunction + "(" + data + ")", 1);
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

